package dfbz.com.service.impl;

import dfbz.com.dao.UserDao;
import dfbz.com.model.Dept;
import dfbz.com.model.User;
import dfbz.com.model.UserFocus;
import dfbz.com.model.UserInfo;
import dfbz.com.service.UserService;


import java.util.Date;
import java.util.List;
import java.util.Map;


/**
 * 在 service 层做业务逻辑处理
 * <p>
 * dao 层只做数据库的查询
 */

public class UserServiceImp implements UserService {
    //userDao与数据库关联，通过username找到对应用户并得到该用户的相关信息——包括密码
    private UserDao userDao = new UserDao();


    @Override
    public User findUser(String username) {

        return userDao.findUserByName(username);

    }

    @Override
    public User findUserByEmail(String email) {
        return userDao.findUserByEmail(email);
    }

    @Override
    public void add(Object o) {
        userDao.add(o);
    }


    @Override
    public void replacePw(User user) {
        userDao.update(user);
    }

    @Override
    public List showUser() {
        return null;
    }


    @Override
    public User findUserById(Object id) {
        User user = (User) userDao.get(id, User.class);
        return user;
    }



    @Override
    public List<Map<String, Object>> showUserByPage2(String current, String row, String search) {
        List<Map<String, Object>> list = userDao.findPageUser2(current, row, search);
        return list;
    }

    @Override
    public List<UserFocus> findFocusUser(Object userId) {
        List<UserFocus> userFocusList = userDao.findUserFocus(userId);

        return userFocusList;
    }

    @Override
    public List<UserFocus> findFocusUser(Object userId, Integer current) {
        List<UserFocus> userFocus = userDao.findUserFocus(userId, current);
        return userFocus;
    }


    @Override
    public List<Map<String, Object>> showUserByPage3(Integer userId, String current, String search) {
        List<Map<String, Object>> list = userDao.findPageUser3(userId, Integer.parseInt(current), search);
        return list;
    }

    @Override
    public long findTotalCount(String search) {
        long total = userDao.findListTotalCount(search);
        return total;
    }

    @Override
    public Dept findDeptName(Integer deptId) {
        Dept dept = (Dept) userDao.get(deptId, Dept.class);
        return dept;
    }

    @Override
    public Boolean updateLoginTime(Integer id) {
        UserInfo userInfo = new UserInfo();
        userInfo.setUserId(id);
        userInfo.setLoginTime(new Date());
        userDao.update(userInfo);
        return true;
    }


}
